package com.boolib.scheck.aop.common.annotation.entity;




import com.boolib.scheck.aop.common.exception.child.ParameterIsNullException;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


@Slf4j
@Aspect
@Component
public class CheckNullAspect {

    @Pointcut("@annotation(com.boolib.scheck.aop.common.annotation.CheckNull)")
    public void checkNull(){}



    @Before("checkNull()")
    public void checkParametersNull(JoinPoint joinPoint) throws ParameterIsNullException {

 


        Object[] objects = joinPoint.getArgs();


        for(Object object :objects){

            if(object instanceof HttpSession) continue;
            if(object instanceof HttpServletRequest) continue;
            if(object instanceof HttpServletResponse) continue;

            if(object instanceof  String){
                if(object == null || object.toString().equals("")){
                    throw new ParameterIsNullException("参数不能空");
                }
            }

            if(object==null){

                throw new ParameterIsNullException("参数不能为空");
            }



        }

    }
}
